﻿package mortal.game.view.copy.sixBoss.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.copy.sixBoss.data.*;
    import mortal.game.view.copy.sixBoss.renderer.*;
    import mortal.game.view.copy.sixBoss.utils.*;
    import mortal.mvc.core.*;

    public class SixBossDamageInfoWin extends CopyInfoPanelBase
    {
        private var _bossName:GTextFiled;
        private var _roleList:GTileList;
        private var _myRank:GTextFiled;
        private var _myDamage:GTextFiled;
        private var _myReward:BaseItem;
        private var _bossList:GTileList;
        private var _lastKiller:GTextFiled;
        private var _lastKill:GTextFiled;
        private var _rewardItem:BaseItem;
        private var _leftTime:SecTimerView;
        private static var _instance:SixBossDamageInfoWin;

        public function SixBossDamageInfoWin()
        {
            super(ImagesConst.copyInfoPanelTitle_sixBoss, 278, 584);
            this.layer = LayerManager.uiLayer;
            this.mouseEnabled = false;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.LMGCRankBg, 0, 0, _bodySprite));
            this._bossName = UIFactory.gTextField(Language.getString(40912), 26, 14 - 4, 233, 25, _bodySprite, GlobalStyle.textFormatHuang2.setSize(14).center());
            this.pushUIToDisposeVec(UIFactory.bg(9, 38 + 4, 260, 23, _bodySprite, ImagesConst.RegionTitleBg));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40913), 13, 43, 28, 20, _bodySprite));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40914), 61, 43, 28, 20, _bodySprite));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40915), 206 - 3, 43, 28, 20, _bodySprite));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40916), 240 - 3, 43, 28, 20, _bodySprite));
            this._roleList = UIFactory.tileList(11, 44 + 21, 267, 252, _bodySprite);
            this._roleList.columnWidth = 262;
            this._roleList.rowHeight = 24;
            this._roleList.horizontalGap = 0;
            this._roleList.verticalGap = 0;
            this._roleList.setStyle("skin", new Bitmap());
            this._roleList.setStyle("cellRenderer", SixBossRoleInfoListCellRenderer);
            this._myRank = UIFactory.gTextField(Language.getString(40917), 17, 293 - 5 + 21, 138, 25, _bodySprite, GlobalStyle.textFormatLv.setSize(14));
            this._myDamage = UIFactory.gTextField("", 229 - 13 - 49 - 28, 293 - 5 + 21, 100, 25, _bodySprite, GlobalStyle.textFormatLv.setSize(14).right());
            this._myReward = UICompomentPool.getUICompoment(BaseItem);
            this._myReward.setItemStyle(20, "", 2, 2);
            this._myReward.x = 241 - 2;
            this._myReward.y = 293 - 5 + 21;
            this._myReward.isShowPrescritime = false;
            _bodySprite.addChild(this._myReward);
            this._lastKiller = UIFactory.gTextField("", 17, 293 - 5 + 21 + 26, 138, 25, _bodySprite, GlobalStyle.textFormatChen.setSize(14));
            this._lastKill = UIFactory.gTextField("", 173 - 49, 293 - 5 + 21 + 26, 138, 25, _bodySprite, GlobalStyle.textFormatHuang2.setSize(14));
            this._rewardItem = UICompomentPool.getUICompoment(BaseItem);
            this._rewardItem.setItemStyle(20, "", 2, 2);
            this._rewardItem.x = 241 - 2;
            this._rewardItem.y = 293 - 5 + 21 + 26;
            this._rewardItem.isShowPrescritime = false;
            _bodySprite.addChild(this._rewardItem);
            this._bossList = UIFactory.tileList(17 - 3, 346 - 5 + 52, 286, 150 + 10, _bodySprite);
            this._bossList.columnWidth = 135;
            this._bossList.rowHeight = 53;
            this._bossList.horizontalGap = 0;
            this._bossList.verticalGap = 0;
            this._bossList.setStyle("skin", new Bitmap());
            this._bossList.setStyle("cellRenderer", SixBossKillInfoCellRenderer);
            this._leftTime = UIFactory.secTimeView(Language.getString(40918), 34 + 80 - 13, 540 + 3, 125, 22, _bodySprite, GlobalStyle.textFormatHuang2.setSize(13));
            this._leftTime.timeOutHandler = this.timeOutHandler;
            this._leftTime.visible = false;
            this.initDamageList();
            this.initBossList();
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.SixBossPlayerHurtRankUpdate, this.onPlayerHurtRankUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.SixBossKillInfoUpdate, this.onBossKillInfoUpdateHandler);
            Dispatcher.addEventListener(EventName.SixBossChangeBoss, this.onChangeBossHandler);
            NetDispatcher.addCmdListener(ServerCommand.SixBossShowResultInfo, this.onKillBossHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.SixBossPlayerHurtRankUpdate, this.onPlayerHurtRankUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.SixBossKillInfoUpdate, this.onBossKillInfoUpdateHandler);
            Dispatcher.removeEventListener(EventName.SixBossChangeBoss, this.onChangeBossHandler);
            NetDispatcher.removeCmdListener(ServerCommand.SixBossShowResultInfo, this.onKillBossHandler);
            return;
        }// end function

        private function initDamageList() : void
        {
            var _loc_1:Array = [];
            var _loc_2:int = 0;
            while (_loc_2 < 10)
            {
                
                _loc_1.push((_loc_2 + 1) + "");
                _loc_2++;
            }
            var _loc_3:* = new DataProvider();
            _loc_3.addItems(_loc_1);
            this._roleList.dataProvider = _loc_3;
            this._roleList.drawNow();
            return;
        }// end function

        private function initBossList() : void
        {
            var _loc_1:Array = [];
            var _loc_2:int = 0;
            while (_loc_2 < 6)
            {
                
                _loc_1.push({});
                _loc_2++;
            }
            var _loc_3:* = new DataProvider();
            _loc_3.addItems(_loc_1);
            this._bossList.dataProvider = _loc_3;
            this._bossList.drawNow();
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            x = Global.stage.stageWidth - 280;
            y = 172 - 25;
            return;
        }// end function

        private function onChallengeHandler(event:MouseEvent) : void
        {
            return;
        }// end function

        private function onPlayerHurtRankUpdateHandler(param1:Object) : void
        {
            var _loc_3:int = 0;
            var _loc_4:DataProvider = null;
            var _loc_5:SixBossOutPutRewardInfo = null;
            var _loc_2:* = Cache.instance.copy.sixBoss.sixBossHurtInfo;
            if (_loc_2)
            {
                _loc_3 = 0;
                while (_loc_3 < _loc_2.topInfos.length)
                {
                    
                    (_loc_2.topInfos[_loc_3] as SMonsterSiegePlayerHurtInfo).rank = _loc_3 + 1;
                    _loc_3++;
                }
                if (_loc_2.topInfos.length > 0)
                {
                    SixBossUtil.HighestDamage = _loc_2.topInfos[0].hurt as int;
                }
                _loc_4 = new DataProvider();
                _loc_4.addItems(_loc_2.topInfos);
                this._roleList.dataProvider = _loc_4;
                this._roleList.drawNow();
                if (_loc_2.myInfo.rank != 0)
                {
                    this._myRank.text = Language.getString(40919) + _loc_2.myInfo.rank;
                    this._myDamage.text = "" + _loc_2.myInfo.hurt;
                }
                _loc_5 = SixBossUtil.getRankRewardByRank(GameController.copy.sixBossCopy.currSelBoss, _loc_2.myInfo.rank);
                if (_loc_5)
                {
                    this._myReward.itemCode = _loc_5.itemCode;
                    this._myReward.amount = _loc_5.itemAmount;
                }
            }
            return;
        }// end function

        private function onBossKillInfoUpdateHandler(param1:Object) : void
        {
            var _loc_3:DataProvider = null;
            var _loc_2:* = Cache.instance.copy.sixBoss.sixBossKillInfo;
            if (_loc_2)
            {
                _loc_3 = new DataProvider();
                _loc_3.addItems(_loc_2.bosses);
                this._bossList.dataProvider = _loc_3;
                this._bossList.drawNow();
            }
            return;
        }// end function

        private function onChangeBossHandler(event:DataEvent) : void
        {
            var _loc_4:SixBossOutPutRewardInfo = null;
            var _loc_2:* = GameController.copy.sixBossCopy.currSelBoss;
            var _loc_3:* = BossConfig.instance.getInfoByCode(_loc_2);
            if (_loc_3)
            {
                this._bossName.text = Language.getStringByParam(40920, _loc_3.name);
                this._lastKiller.text = Language.getString(40921);
                this._lastKill.text = Language.getString(40922);
                _loc_4 = SixBossUtil.getRankRewardByRank(_loc_2, 0);
                this._rewardItem.itemCode = _loc_4.itemCode;
                this._rewardItem.amount = _loc_4.itemAmount;
            }
            else
            {
                this._bossName.text = Language.getString(40923);
            }
            return;
        }// end function

        private function onKillBossHandler(param1:Object) : void
        {
            var _loc_2:* = param1 as SMonsterSiegeResultMsg;
            if (_loc_2)
            {
                this._lastKiller.text = _loc_2.killName;
                this._lastKill.text = Language.getString(40922);
            }
            return;
        }// end function

        private function clearRankInfo() : void
        {
            this.initDamageList();
            this._myRank.text = Language.getString(40924);
            this._myDamage.text = "";
            this._lastKill.text = "";
            this._lastKiller.text = "";
            this._rewardItem.itemData = null;
            return;
        }// end function

        private function updateLeftTime() : void
        {
            var _loc_1:Date = null;
            var _loc_2:Date = null;
            var _loc_3:Date = null;
            var _loc_4:int = 0;
            if (Cache.instance.copy.treasureHunt.treasureHuntTimeInfo)
            {
                _loc_1 = ClockManager.instance.nowDate;
                _loc_2 = Cache.instance.copy.sixBoss.sixBossTimeInfo.startDt;
                _loc_3 = Cache.instance.copy.sixBoss.sixBossTimeInfo.endDt;
                _loc_4 = (_loc_3.time - _loc_1.time) * 0.001;
                this._leftTime.setLeftTime(_loc_4);
            }
            return;
        }// end function

        private function timeOutHandler() : void
        {
            if (this._leftTime)
            {
                this._leftTime.stop();
                this._leftTime.visible = false;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._bossName.dispose();
            this._bossName = null;
            this._roleList.dispose();
            this._roleList = null;
            this._myRank.dispose();
            this._myRank = null;
            this._myDamage.dispose();
            this._myDamage = null;
            this._bossList.dispose();
            this._bossList = null;
            this._lastKiller.dispose();
            this._lastKiller = null;
            this._lastKill.dispose();
            this._lastKill = null;
            this._rewardItem.dispose();
            this._rewardItem = null;
            this._myReward.dispose();
            this._myReward = null;
            this._leftTime.dispose();
            this._leftTime = null;
            this.removeListeners();
            return;
        }// end function

        public static function get instance() : SixBossDamageInfoWin
        {
            if (_instance == null)
            {
                _instance = new SixBossDamageInfoWin;
            }
            return _instance;
        }// end function

    }
}
